﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Net;

using HtmlAgilityPack;

namespace WCrawlerLib.WebSession
{
    public interface IForumSession
    {
        #region Properties
        Forum ObjForum { get; set; }
        #endregion

        #region Methods

        IForumSession GetInstance(int forumId);
        #region Login

        /// <summary>
        /// Login in a forum. If susscessful set _isLogged = true, else false
        /// </summary>
        bool DoLogin();

        /// <summary>
        /// Get id of account
        /// </summary>
        /// <returns></returns>
        int GetAccountId();
       
        //void PostNewThread(string subject, string message, string fId, string iconId, string tagList, string prefixId);
        void PostNewThread(Post objPost);
        bool PostNewReply(string topicUrl, string newReplyUrl, string postParams, string message);
        bool PostEdit(string forumUrl, string topicUrl, string postId, string editParams, string subject, string message, string updateReason, string icon);
        void CheckForumInfo();

        #endregion

        #endregion
    } 

    public interface ITempForum
    {
        /// <summary>
        /// Check authentication before Get or Post
        /// </summary>
        object IsAuthentication { get; set; }

        int GetUserId(string forumUrl, string userName);

        int GetUserIdAfterLogin();


        #region Virtual Functions

        /// <summary>
        /// Init params of POST  to login a forum.
        /// </summary>
        string InitLoginParams(string postParams, params string[] pars);//(string username, string password);

        string InitNewThreadParams(string postParams, params string[] values);//, string subject, string message, string fId, string icon, string tagList);

        string InitNewReplyParams(string postParams, string message);



        void PostNewThread(string forumUrl, string newThreadurl, string postParams, string subject, string message, string fId, string icon, string tagList, string prefixId);

        bool PostReply(string topicUrl, string forumUrl, string message);

        bool PostNewReply(string forumUrl, string topicUrl, string newReplyUrl, string postParams, string message);

        bool EditPost(string forumUrl, string topicUrl, string postId, string editParams, string subject, string message, string updateReason, string icon);

        List<DataRow> SearchThreadsByPaging(string forumUrl, HtmlDocument doc, DataTable table);

        string SearchThreadsInTopic(string postTitle, string topicUrl, string searchTopic_xPath, string username);

        DataTable SearchForumThreads(string forumUrl, string statisticUrl, string xPath_Paging, DataTable table, bool isPaging, bool isGetFirstThreads);

        /// <summary>
        /// Get thread num and post num in thread url
        /// </summary>
        /// <param name="threadUrl"></param>
        /// <returns></returns>
        string[] GetThreadPostNum(string threadUrl);

        /// <summary>
        /// Get thread num and post num in thread url
        /// </summary>
        /// <param name="threadUrl"></param>
        /// <returns></returns>
        string[] GetThreadPostNum(HtmlDocument doc);


        #endregion

        #region Forum HtmlDocument
        /// <summary>
        /// Get group title include titles of subforums 
        /// .//ol/li[.//a[contains(@href,'forumdisplay.php');]] 
        /// .//ol/li//a[not(contains(@href,'.html'););]
        /// </summary>
        /// <param name="forum"></param>
        /// <param name="xPath"></param>
        /// <returns></returns>
        Dictionary<string, string> SearchTopics(HtmlDocument doc, string xPath, string blackListUrl);

        /// <summary>
        /// Return result in two key "type" and "forumtype" of Dictionary
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        Dictionary<string, string> GetForumType(HtmlDocument doc);
        #endregion

        bool Authentication();

        string FValue_Pattern();

        /// <summary>
        /// Search f value in button New Thread with url template do=newthread&f=[number]
        /// </summary>
        /// <param name="threadUrl"></param>
        /// <returns></returns>
        string FindNewThreadValue(string threadUrl, string pattern);

        /// <summary>
        /// Use alexa rank to indentify the rank and location of the forum
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        Dictionary<string, string> GetAlexaRank(string forumUrl);

        /// <summary>
        /// Download image from image url
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="url"></param>
        string DownloadImage(string imageUrl, string localpath, string fileName);

        byte[] ProcessImageStream(HttpWebResponse resp);

        /// <summary>
        /// Get value by regex pattern
        /// </summary>
        /// <param name="pattern"></param>
        string GetValueByRegexPattern(string pattern);
    }
    
}
